﻿<Window
    x:Class="PyBindingTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="PyBindingTest"
    Height="600"
    Width="800"
    xmlns:p="clr-namespace:PyBinding;assembly=PyBinding"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:l="clr-namespace:PyBindingTest">
    <Window.Resources>
        <DataTemplate
            DataType="{x:Type l:Person}">
            <TextBlock
                Text="{p:PyBinding 2*$[TheSlider.Value]}"
                FontSize="6"
                Width="100" />
        </DataTemplate>

        <SolidColorBrush x:Key="RedBrush" Color="Red" />
        <SolidColorBrush x:Key="GreenBrush" Color="Green" />
        <sys:String
            x:Key="SomeString">
            SomeString
        </sys:String>

    </Window.Resources>

    <Window.DataContext>
        <l:MainPresenter
            Name="NameOfMainPresenter" />
    </Window.DataContext>
    <StackPanel>
        <TextBlock
            Text="{p:PyBinding \'Null\' if $[.People] \=\= None else \'Not Null\'}"
            FontSize="6"
            Width="100" />
        <Button
            Content="Null"
            Click="OnNullDataSource" />
        <TextBlock
            x:Name="One"
            Text="{p:PyBinding $[.People[0].Age]}" />

        <StackPanel Orientation="Horizontal">
            <TextBlock Text="Slide this slider:" FontSize="18"/>
            <Slider x:Name="TheSlider"
                    Maximum="200" 
                    Width="200"/>
        </StackPanel>
        <TextBlock x:Name="Two" Text="Will be red half, then green">
            <TextBlock.Foreground>
                <p:PyBinding Script="var_1 if var_0 &gt; 100 else var_2">
                    <Binding ElementName="TheSlider" Path="Value" />
                    <Binding Source="{StaticResource RedBrush}" />
                    <Binding Source="{StaticResource GreenBrush}" />
                </p:PyBinding>
            </TextBlock.Foreground>
        </TextBlock>

        <TextBlock
            x:Name="Three"
            Text="Now you see me">
            <TextBlock.Visibility>
                <p:PyBinding Script="BooleanToVisibility(var_0 &gt; 25)">
                       <Binding ElementName="TheSlider" Path="Value" />
                </p:PyBinding>
            </TextBlock.Visibility>
        </TextBlock>


        <TextBlock Text="{p:PyBinding $[TheSlider.Value], StringFormat={}{0:n2}}" />

        <Polyline
            Points="{p:PyBinding PointCollection([Point(1\,0.5*$[TheSlider.Value])\, Point(3\,4)])}"
            Stroke="Black"
            StrokeThickness="2"
            Stretch="Fill"/>
        <ListBox ItemsSource="{Binding People}"/>
    </StackPanel>
</Window>
